package com.xingxing.Activity;

import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.google.gson.Gson;
import com.xingxing.Activity.databinding.ActivityEditProfileBinding;
import com.xingxing.Interface.OkSuccessInterface;
import com.xingxing.Util.APIConfig;
import com.xuexiang.xui.utils.StatusBarUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import static com.xingxing.Util.CommonUtils.GetUserInfo;
import static com.xingxing.Util.CommonUtils.OKJsonPost;

public class EditProfileActivity extends AppCompatActivity {
    private ActivityEditProfileBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_edit_profile);
        binding = ActivityEditProfileBinding.inflate(getLayoutInflater());
        //设置沉浸式状态栏
        StatusBarUtils.translucent(this);
        //设置黑色字体状态栏
        StatusBarUtils.setStatusBarLightMode(this);
        setContentView(binding.getRoot());
        binding.btnEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (binding.etNickName.getText().toString().isEmpty()) {
                    Toast.makeText(getApplicationContext(), "请将内容填写完成!", Toast.LENGTH_SHORT).show();
                } else {
                    binding.btnEdit.setEnabled(false);
                    Map<String, Object> map = new HashMap<>();
                    map.put("userAccount", Objects.requireNonNull(GetUserInfo()).getUserAccount());
                    map.put("userNickName", binding.etNickName.getText().toString());
                    OKJsonPost(EditProfileActivity.this, new Gson().toJson(map), APIConfig.LoginByEmailCode, new OkSuccessInterface() {
                        @Override
                        public void OnSuccess(String json) {
                            Map<String, Object> map = new HashMap<>();
                            map = new Gson().fromJson(json, map.getClass());
                            Toast.makeText(getApplicationContext(), (String) map.get("status"), Toast.LENGTH_SHORT).show();
                        }
                    });
                    binding.btnEdit.setEnabled(true);
                }
            }
        });
    }
}